package com.xueyiyue.xueyiyue.controller;

import com.xueyiyue.xueyiyue.model.entity.City;
import com.xueyiyue.xueyiyue.model.entity.District;
import com.xueyiyue.xueyiyue.model.entity.Province;
import com.xueyiyue.xueyiyue.model.sys.ApiResult;
import com.xueyiyue.xueyiyue.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author chenlixian
 * @description TODO
 * @date 2021/2/20 11:39
 */
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {
    @Autowired
    private CommonService commonService;
    // 获取省份
    @ResponseBody
    @RequestMapping(value = "/getProvince",method = RequestMethod.POST)
    public ApiResult getProvince() {
        List<Province> provinces = commonService.getProvince();
        log.info("获取省份",provinces);
        return ApiResult.ok(provinces);
    }
    @ResponseBody
    @RequestMapping(value = "/getCity",method = RequestMethod.POST)
    public ApiResult getCity(@RequestBody Map<String,String> map) {
        String provinceId = map.get("provinceId");
        List<City> cities = commonService.getCity(provinceId);
        log.info("获取城市",cities);
        return ApiResult.ok(cities);
    }
    @ResponseBody
    @RequestMapping(value = "/getDistrict",method = RequestMethod.POST)
    public ApiResult getDistrict(@RequestBody Map<String,String> map) {
        String cityId = map.get("cityId");
        List<District> districts = commonService.getDistrict(cityId);
        log.info("获取区",districts);
        return ApiResult.ok(districts);
    }


}